<template>
    <div class="center-page text-center">
      <div class="div-img" v-if="!showDiv">
        <img src="./../../static/lib/img/30.gif">
      </div>
      <w-error v-else></w-error>
    </div>
</template>

<script>
import { Dialog } from 'vant';
import wError from './error';
import * as api from './../api/api.js';
export default {
  name:'nav-tab',
  data(){
    return{
        showDiv:false
    }
  },
  created(){
    if(this.stateParam('code')&&this.stateParam('state')){
      this.fetchToLogin(this.stateParam('code'),this.stateParam('state'))
    }else{
      this.showDiv=true;
      Dialog.alert({
        title: '标题',
        message: '无法获取数据，请稍后重试'
      })
    }

    // this.fetchToLogin('081UQWfL1kFBL41nVrfL1xbcgL1UQWf1','dashBoard')
   
  },
  methods:{
    jumpLink(url){
      this.$router.replace({name:url});
    },
    fetchToLogin(code,state){
      let vm = this;
      let body={
        code:code
      };
      // api.preapareToLogin(body).then(res=>{
      //   sessionStorage.setItem("wxInfo", JSON.stringify(res.data.wxInfo)); 
      //   if(res.data.data=='001'){
      //     vm.jumpLink(state);
      //   }else if(res.data.data=='002'){
      //     sessionStorage.setItem("stateUrl", state); 
      //     vm.$router.replace({name:'login'})
      //   }
      // })
    },
    stateParam:function (name){
        var url = window.location.href;
        var theRequest = new Object();
        if (url.indexOf('?') != -1) {
            var str = url.substr(1);
            var strs = str.split('?');
            var search= strs[1].split('&');
            for(var i=0; i<search.length; i++) {
                if(search[i].split('=')[0] == name){
                    return search[i].split('=')[1].split('#')[0];
                }
            }
        }
    },
  },
  mounted(){
    let vm = this;
    // setTimeout(()=>{
    //   vm.jumpLink();
    // },3000)
  },
  components:{
    wError
  }
}
</script>


<style scoped lang="scss">
  .center-page {
    background:#fff;
    height:100%;
    padding-top:60%;
    color: #5a5a5a;
    box-sizing:border-box;
    .div-img{
        height:.533333rem;
    }
    img{
      height:100%;
    }
  }
</style>
